import 'package:flutter_web/material.dart';

import 'package:zz_blog/common/screen.dart';
import 'package:zz_blog/model/bloc/hitokoto_bloc.dart';
import 'package:zz_blog/model/bloc_provider.dart';

class HitokotoFragemnt extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    HitokotoBloc hitokotoBloc = BlocProvider.of<HitokotoBloc>(context);
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (hitokotoBloc.hitokoto.id == 0) {
        hitokotoBloc.init();
      }
    });
    return Padding(
      padding: EdgeInsets.symmetric(
        horizontal: 50,
        vertical: 10,
      ),
      child: StreamBuilder(
        initialData: hitokotoBloc.hitokoto,
        stream: hitokotoBloc.hitokotoStream,
        builder: (_, snapshot) => SizedBox(
          width: Screen.realWidth - 100,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text(
                    '『',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                  Expanded(
                    child: Center(
                      child: Padding(
                        padding: EdgeInsets.symmetric(
                          horizontal: 50,
                          vertical: 15,
                        ),
                        child: Text(
                          snapshot.data.hitokoto,
                          style: TextStyle(
                            fontSize: 18,
                          ),
                        ),
                      ),
                    ),
                  ),
                  Text(
                    '』',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                ],
              ),
              Align(
                alignment: Alignment.centerRight,
                child: Text(
                  '------（${snapshot.data.typeText}）${snapshot.data.from}',
                  style: TextStyle(
                    fontSize: 18,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
